import 'package:fate_blind_box/network/http_request.dart';
import 'package:fate_blind_box/utils/provider.dart';
import 'package:flutter/cupertino.dart';
import 'package:get/get.dart';

import '../../../utils/loading.dart';
import 'act_details_model.dart';

class ActDetailsController extends GetxController {
  String detailsViewId = 'detailsViewId';
  ActDetailsDataModel detailsModel = ActDetailsDataModel();
  TextEditingController inputController = TextEditingController();

  //报名详情
  getDetailsData(String actId) async {
    var res = await HttpRequest.request('member/activity/blindDetails',
        params: {'activityId': actId,'memberId':Provider.memberId});
    if (res is Map) {
      Map resMap = res;
      ActDetailsModel resData = ActDetailsModel.fromJson(resMap);
      detailsModel = resData.data ?? ActDetailsDataModel();
      inputController.text=detailsModel.actiPhone??'';
      update([detailsViewId]);
    }
  }

  //添加报名
  addSignUpAction({String actId='',String phoneStr=''}) async {
    var res = await HttpRequest.request('member/activity/join',
        params: {'activityId': actId,'actiPhone':phoneStr});
    if (res['code'] == 0) {
      final data = res['data'];
      if (data != null) {
        toast('保存成功');
        Get.back();
      } else {
        toast(res['msg']);
      }
    }
  }

  String getSignStatus(int sign){
    String name='报名';
    switch(sign){
      case -1:
        return '已结束';
      case 0:
        return '已开始';
      case 1:
        return name;
      case 2:
        return '已报名';
    }
    return name;
  }
}
